package com.xmhmyh.generalframework.common.print;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;

/**
 * @Author: 于丁
 * @DateTime: 2020/9/23 4:36 下午
 */
public class MyFontProvider extends XMLWorkerFontProvider {

    @Value("${printFontPath}")
    private String printFontPath;

    public MyFontProvider() {
        super(null, null);
    }

    @Override
    public Font getFont(final String fontname, String encoding, float size, final int style) {
        BaseFont fontChinese = null;
        try {
            fontChinese = BaseFont.createFont("/Users/yuding/Desktop/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Font normalFont = new Font(fontChinese, 12);
        return normalFont;
    }
}
